<?php
//管理员操作记录管理
namespace app\adminbackstage\model;

use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Operation extends Model{

    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }

    
    //管理员操作记录信息
    public function operationFind($page=1,$num=10,$where){
        $list = $this::name('operation')
        ->where($where)
        ->limit(($page-1)*$num,$num)
        ->select();
        return $list;
   
    }
    
    //管理员操作记录添加
    public  function operationAdd(array $data){
        return self::create($data);
    }
    
        //管理员操作记录添加
    public  function operationAddAll(array $data){
        return self::insertAll($data);
    }


    //石榴籽发放记录获取
    public function operationGoldFind($where,$page,$num){
        return  $this::name('operation')
            ->alias('o')
            ->field('o.id,o.addtime,o.operation,g.num_gold,u1.phone,ua.username')
            ->join('gold g','g.id = o.mt_id')
            ->join('user u1','u1.uid = g.uid')
            ->join('user ua','ua.uid = o.uid')
            ->where($where)
            ->order('o.id desc')
            ->page($page,$num)
            ->select();
    }

    //石榴籽发放总条数获取
    public function operationGoldCount($where){
        return  $this::name('operation')
            ->alias('o')
            ->join('gold g','g.id = o.mt_id')
            ->join('user u1','u1.uid = g.uid')
            ->join('user ua','ua.uid = o.uid')
            ->where($where)
            ->count();
    }

    //添加店铺名额 --发放列表
    public function operationShopList($where,$page,$num){
        return  $this::name('operation')
            ->alias('o')
            ->field('o.id,o.operation,o.addtime,u1.phone,ua.username')
            ->join('user u1','u1.uid = o.mt_id')
            ->join('user ua','ua.uid = o.uid')
            ->where($where)
            ->order('o.id desc')
            ->page($page,$num)
            ->select();
    }

    //添加店铺名称 -- 获取数据总条数
    public function operationShopCount($where){
        return  $this::name('operation')
            ->alias('o')
            ->join('user u1','u1.uid = o.mt_id')
            ->join('user ua','ua.uid = o.uid')
            ->where($where)
            ->count();
    }
    
    
    //石榴籽扣除记录获取
    public function deductionGoldFind($where,$page,$num){
        return  $this::name('operation')
            ->alias('o')
            ->field('o.id,o.addtime,o.operation,g.gold as num_gold,u1.phone,ua.username')
            ->join('gold_detailed g','g.id = o.mt_id')
            ->join('user u1','u1.uid = g.uid')
            ->join('user ua','ua.uid = o.uid')
            ->where($where)
            ->order('o.id desc')
            ->page($page,$num)
            ->select();
    }

    //石榴籽扣除总条数获取
    public function deductionGoldCount($where){
        return  $this::name('operation')
            ->alias('o')
            ->join('gold_detailed g','g.id = o.mt_id')
            ->join('user u1','u1.uid = g.uid')
            ->join('user ua','ua.uid = o.uid')
            ->where($where)
            ->count();
    }
    
    
    //添加店铺名额 --发放列表
    public function currencyList($where,$page,$num){
        return  $this::name('operation')
            ->alias('o')
            ->field('o.id,o.operation,o.addtime,o.remarks,u1.phone,u2.username,m.amount_currency')
            ->leftjoin('merchant_currency_detailed m','m.id = o.mt_id')
            ->leftjoin('user u1','u1.uid = m.uid')
            ->leftJoin('user u2','u2.uid = o.uid')
            ->where($where)
            ->order('o.id desc')
            ->page($page,$num)
            ->select();
    }

    //添加店铺名称 -- 获取数据总条数
    public function currencyCount($where){
        return  $this::name('operation')
            ->alias('o')
            ->leftjoin('merchant_currency_detailed m','m.id = o.mt_id')
            ->leftjoin('user u1','u1.uid = m.uid')
            ->leftJoin('user u2','u2.uid = o.uid')
            ->where($where)
            ->count();
    }
    
    
}
